package www.shuang.orders.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import www.shuang.common.util.PageInfoUtil;
import www.shuang.orders.dao.IAOrdersDao;
import www.shuang.orders.dao.IAOrdersHistoryDao;
import www.shuang.orders.dao.IAOrdersPayDao;
import www.shuang.orders.dao.IAOrdersPayHistoryDao;
import www.shuang.orders.pojo.AOrders;
import www.shuang.orders.pojo.AOrdersHistory;
import www.shuang.orders.pojo.AOrdersPay;
import www.shuang.orders.pojo.AOrdersPayHistory;
import www.shuang.orders.service.AOrdersService;

@Service("ordersService")
public class IAOrdersServiceImpl implements AOrdersService
{	@Resource
	protected IAOrdersDao ordersDao;
	@Resource
	private IAOrdersHistoryDao ordersHistoryDao;
	@Resource
	private IAOrdersPayDao ordersPayDao;
	@Resource
	private IAOrdersPayHistoryDao ordersPayHistoryDao;
	@Override
	public AOrders findOneAOrdersService(Map<String, Object> condMap)
	{
		return this.ordersDao.findOne(condMap);
	}

	@Override
	public List<AOrders> findCondListAOrdersService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		return null;
	}

	@Override
	public JSONObject insertOneAOrdersService(AOrders orders)
	{
		JSONObject resultJSON=new JSONObject();
		int res=this.ordersDao.insert(orders);
		//保存订单
		if(res>0){
			resultJSON.put("code", "0");
			resultJSON.put("info", "添加成功");
			//二级json
			JSONObject dataJSON=new JSONObject();
			dataJSON.put("code", "2");
			resultJSON.put("affect", dataJSON);
			//保存订单历史
			AOrdersHistory ordersHistory=new AOrdersHistory();
			ordersHistory.setOrdersId(orders.getId());
			ordersHistory.setContent("贷款金额;利率"+orders.getLoanRate()+";贷款金额"+orders.getLoanMoney());
			ordersHistory.setStatus(orders.getStatus());
			ordersHistory.setCreateTime(new Date());
			ordersHistory.setUpdateTime(new Date());
			//调用service方法
			this.insertOneOrdersHistoryService(ordersHistory);
		}
		else {
			resultJSON.put("code", "1");
			resultJSON.put("info", "添加失败");
		}
		return resultJSON;
	}

	@Override
	public JSONObject updateOneAOrdersService(AOrders orders)
	{
		return null;
	}

	@Override
	public JSONObject deleteOneAOrdersService(AOrders orders)
	{
		return null;
	}

	@Override
	public List<AOrders> findCondListOrdersService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		return this.ordersDao.findCondList(condMap);
	}

	@Override
	public JSONObject insertOneOrdersHistoryService(AOrdersHistory ordersHistory)
	{
		return null;
	}

	@Override
	public JSONObject updateOneOrdersHistoryService(AOrdersHistory ordersHistory)
	{
		return null;
	}

	@Override
	public AOrdersHistory findOneOrdersHistoryService(Map<String, Object> condMap)
	{
		return this.ordersHistoryDao.findOne(condMap);
	}

	@Override
	public List<AOrdersHistory> findCondListOrdersHistoryService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		return null;
	}

	@Override
	public AOrdersPay findOneOrdersPayService(Map<String, Object> condMap)
	{
		return this.ordersPayDao.findOne(condMap);
	}

	@Override
	public List<AOrdersPay> findCondListOrdersPayService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		return null;
	}

	@Override
	public AOrdersPayHistory findOneOrdersPayHistoryService(Map<String, Object> condMap)
	{
		return this.ordersPayHistoryDao.findOne(condMap);
	}

	@Override
	public List<AOrdersPayHistory> findCondListOrdersPayHistoryService(PageInfoUtil pageInfoUtil,
			Map<String, Object> condMap)
	{
		return null;
	}

}
